$(function () {
    $("#jqGrid").jqGrid({
        url: '../shorderinfo/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden:true},
			{ label: '售后服务--表单', name: 'singleId', index: 'single_id', width: 80 }, 			
			{ label: '设备编号psn', name: 'deviceCode', index: 'device_code', width: 80 }, 			
			{ label: '用户姓名', name: 'userName', index: 'user_name', width: 80 }, 			
			{ label: '用户联系方式', name: 'userPhone', index: 'user_phone', width: 80 }, 			
			{ label: '用户邮箱', name: 'userEmail', index: 'user_email', width: 80 }, 			
			{ label: '问题描述', name: 'questionDescription', index: 'question_description', width: 80 }, 			
			{ label: '问题图片路径  （多张图片路径拼接   ，）', name: 'questionImagePath', index: 'question_image_path', width: 80 }, 			
			{ label: '0为删除数据状态', name: 'status', index: 'status', width: 80 }, 			
			{ label: '订单状态主键', name: 'orderStatusId', index: 'order_status_id', width: 80 }, 			
			{ label: '数据添加时间', name: 'addTime', index: 'add_time', width: 80 }, 			
			{ label: '用户标示', name: 'userId', index: 'user_id', width: 80 }, 			
			{ label: '订单编号', name: 'orderId', index: 'order_id', width: 80 }, 			
			{ label: '订单金额(实际支付金额)', name: 'orderPrice', index: 'order_price', width: 80 }, 			
			{ label: '物流编号(用户寄出)', name: 'orderLogisticsCode', index: 'order_logistics_code', width: 80 }, 			
			{ label: '订单详情的描述信息(维修方案)', name: 'orderDetail', index: 'order_detail', width: 80 }, 			
			{ label: '收件人姓名', name: 'recipientName', index: 'recipient_name', width: 80 }, 			
			{ label: '收件人手机号', name: 'recipientPhone', index: 'recipient_phone', width: 80 }, 			
			{ label: '收件人地址', name: 'recipientAddress', index: 'recipient_address', width: 80 }, 			
			{ label: '用户取消申请原因字段', name: 'userWithdrawCause', index: 'user_withdraw_cause', width: 80 }, 			
			{ label: '客服取消订单原因字段', name: 'customServiceWithdrawCause', index: 'custom_service_withdraw_cause', width: 80 }, 			
			{ label: '上一个状态', name: 'previousStatus', index: 'previous_status', width: 80 }, 			
			{ label: '操作人', name: 'operatorId', index: 'operator_id', width: 80 }, 			
			{ label: '操作时间', name: 'operatorTime', index: 'operator_time', width: 80 }, 			
			{ label: '订单取消时间', name: 'orderCancelTime', index: 'order_cancel_time', width: 80 }, 			
			{ label: '用户签收时间', name: 'userSignTime', index: 'user_sign_time', width: 80 }, 			
			{ label: '订单结束时间（用户不手动点结束，15天自动结束）', name: 'orderEndTime', index: 'order_end_time', width: 80 }, 			
			{ label: '支付完成时间', name: 'orderPlayTime', index: 'order_play_time', width: 80 }, 			
			{ label: '1（交由我司）0：自行处理 复选框 建议交由我们处理废弃电子元件 字段', name: 'partsStatus', index: 'parts_status', width: 80 }, 			
			{ label: '1 powerEgg 2eye 3ray', name: 'proId', index: 'pro_id', width: 80 }, 			
			{ label: '寄回运单号', name: 'sendNumber', index: 'send_number', width: 80 }, 			
			{ label: '规格型号', name: 'normsNumber', index: 'norms_number', width: 80 }, 			
			{ label: '地区(cn,en,uk)', name: 'countryArea', index: 'country_area', width: 80 }, 			
			{ label: '服务类型id', name: 'serviceTypeId', index: 'service_type_id', width: 80 }, 			
			{ label: '购买时的订单id', name: 'buyOrderId', index: 'buy_order_id', width: 80 }, 			
			{ label: '用户退款银行帐号', name: 'bankNo', index: 'bank_no', width: 80 }, 			
			{ label: '用户退款银行名称', name: 'bankName', index: 'bank_name', width: 80 }, 			
			{ label: '退款人姓名', name: 'reimburseName', index: 'reimburse_name', width: 80 }, 			
			{ label: '换货时新的psn码', name: 'newDeviceCode', index: 'new_device_code', width: 80 }, 			
			{ label: '问题id（1，2，3）', name: 'questionId', index: 'question_id', width: 80 }, 			
			{ label: '维修金额', name: 'repairPrice', index: 'repair_price', width: 80 }, 			
			{ label: '支付类型(2保险支付，1原价，3免费)', name: 'payType', index: 'pay_type', width: 80 }, 			
			{ label: '保险id', name: 'insuranceId', index: 'insurance_id', width: 80 }, 			
			{ label: '责任类型（0用户,1公司）', name: 'dutyType', index: 'duty_type', width: 80 }, 			
			{ label: '故障类型1', name: 'malfunctionCodeFirst', index: 'malfunction_code_first', width: 80 }, 			
			{ label: '故障详情1', name: 'malfunctionCodeDetailFirst', index: 'malfunction_code_detail_first', width: 80 }, 			
			{ label: '故障原因1', name: 'malfunctionReasonCodeFirst', index: 'malfunction_reason_code_first', width: 80 }, 			
			{ label: '故障原因1详情', name: 'malfunctionReasonCodeDetailFirst', index: 'malfunction_reason_code_detail_first', width: 80 }, 			
			{ label: '故障2', name: 'malfunctionCodeSecond', index: 'malfunction_code_second', width: 80 }, 			
			{ label: '故障详情2', name: 'malfunctionCodeDetailSecond', index: 'malfunction_code_detail_second', width: 80 }, 			
			{ label: '故障原因1', name: 'malfunctionReasonCodeSecond', index: 'malfunction_reason_code_second', width: 80 }, 			
			{ label: '故障原因详情2', name: 'malfunctionReasonCodeDetailSecond', index: 'malfunction_reason_code_detail_second', width: 80 }, 			
			{ label: '故障2', name: 'malfunctionCodeThird', index: 'malfunction_code_third', width: 80 }, 			
			{ label: '故障详情3', name: 'malfunctionCodeDetailThird', index: 'malfunction_code_detail_third', width: 80 }, 			
			{ label: '故障原因3', name: 'malfunctionReasonCodeThird', index: 'malfunction_reason_code_third', width: 80 }, 			
			{ label: '故障原因详情3', name: 'malfunctionReasonCodeDetailThird', index: 'malfunction_reason_code_detail_third', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		shOrderInfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.shOrderInfo = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.shOrderInfo.id == null ? "../shorderinfo/save" : "../shorderinfo/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.shOrderInfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../shorderinfo/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../shorderinfo/info/"+id, function(r){
                vm.shOrderInfo = r.shOrderInfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});